package com.orientation.utils;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;
/**
 * @Description:
 * @PROJECT_NAME: orientation
 * @PACKAGE_NAME: com.orientation.utils
 * @NAME: AesUtil
 * @author:xuandian
 * @Version: 1.0
 * @DATE: 2022/1/2 15:28
 */
public class AesUtil {
    //Aes加密算法
    private static final SecretKey secretKey = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), "1234567890abcdef".getBytes(StandardCharsets.UTF_8));
    //密码加密
    private static final SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, secretKey);

    //密码解密
    public static String encrypt(String s) {
        return aes.encryptHex(s);
    }

    //aes算法
    public static String decrypt(String s) {
        return aes.decryptStr(s, CharsetUtil.CHARSET_UTF_8);
    }
}
